<?php 

插入数据

 insert into student (name,sex,age) values('温远坤','女','18'),('汪晓波','男','34'),('雷振强','男','25');


 全表查询：

select * from student;

 单个字段查询 ：
select name,sex from student;

别名：
select name as student_name,sex as student_sex from student;

简写别名：
select name student_name,sex  student_sex from student;


单条件：

select * from student where id = 4;

select * from student where score='100';

多条件查询：

二边成立  与
select * from student where sex='男' and score='100';

一边成立  或
select * from student where sex='女' or score='100';

非
select * from student where sex<>'女';
select * from student where sex!='女';


大于

select * from student where age>33;


链接符：

select concat(name,sex) text from student where age>20;


select age,age>20 from student;

select age,if(age>20,'大龄青年','小鲜肉') as zhenlei  from student;


过滤重复


select distinct score from student;

like过虑

select * from student where hobby like '%泡妞%';


select * from student where FIND_IN_SET('写代码',hobby);


null判断 

 select * from student where comment is null;


 select * from student where comment is not null;

 select name,ifnull(comment,'没有备注') comment from student;


 排序：

select * from student order by age desc; 倒序

select * from student order by age asc; 正序


取几条：

select * from student limit 3;

取得分的前三名
select * from student order by score desc limit 3;


从第几条，取几条
select * from student limit 3,3;

between 什么与什么之间
select * from student where age between 10 and 20 ;
相当于这个:select * from student where age>10 and age< 20 ;

in  在什么里面
select * from student where age in (34,28,18);


not between 不在什么与什么之间
select * from student where age not between 10 and 20 ;


not in  不在什么里面
select * from student where age in (34,28,18);

like 匹配

select * from student where comment like '%结%';


not like 不匹配
select * from student where comment not like '%结%';

截取字符串

select left(name,1) name from student;

select mid(name,2,1) name from student;

select right(name,2) name from student;



show variables like "%character%";



create table a(
	name varchar(30) character set utf8 collate  utf8_bin,
	name2 varchar(30) character set utf8 collate  utf8_general_ci
	);























 ?>